###app.py

##导入依赖库
from flask import Flask
import datetime
import config
from flask_apscheduler import APScheduler
from apscheduler.schedulers.background import BackgroundScheduler

# 创建Flask对象
app = Flask(__name__)
# 配置执行器
app.config['SCHEDULER_EXECUTORS'] = {'default': {'type': 'threadpool', 'max_workers': 10}}
# 配置作业存储器
app.config['SCHEDULER_JOBSTORES'] = {'default': {'type': 'memory'}}
app.config.from_object(config.Config)

# 创建APScheduler对象，调度器是BackgroundScheduler
scheduler = APScheduler(scheduler=BackgroundScheduler(daemon=True))
scheduler.init_app(app)
scheduler.start()


# 定义任务
def api_task():
    current_time = datetime.datetime.now()
    print("API调用定时任务开始执行时间：{}".format(current_time))


# 以调用API的方式定义定时任务
scheduler.add_job(id='do_job_2', func=api_task, trigger='interval', seconds=1)

if __name__ == '__main__':
    app.run()





